package com.example.springboot.web;

import com.example.springboot.mapper.TestMapper;

import com.example.springboot.vo.Person;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j  // 自动生产 log 对象
public class IndexAction {

    @RequestMapping("hello")
    public String hello(
            @RequestParam(defaultValue = "SpringBoot") String name){
        return "hello " + name;
    }

    @Value("${demo.name}")
    String myname;
    @Value("${demo.age:100}")
    int age;

    @GetMapping("myinfo")
    public String myinfo(){
        return myname + ":" + age;
    }

    @Resource
    Person person;
    @GetMapping("myFamily")
    public Person myFamily(){
        log.info("信息日志");
        log.error("错误日志");
        return person;
    }

    @Resource
    TestMapper testMapper;

    @GetMapping("queryAccount")
    public List<?> queryAccount(){
        return testMapper.selectAllAccount();
    }
}
